﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ProcessFile;

namespace ICD2ADDesignRule
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnImoport_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "Stackup Planner file (.stk)|*.stk|All Files (*.*)|*.*";
            if (dialog.ShowDialog()==DialogResult.OK)
            {
                txtIcd.Text = dialog.FileName;
            }
        }

       

        private void btnExportToAd14_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();
            saveFileDialog1.InitialDirectory = Convert.ToString(Environment.SpecialFolder.MyDocuments);
            saveFileDialog1.Filter = "AD Design Rule(*.RUL)|*.RUL|All Files (*.*)|*.*";
            saveFileDialog1.FilterIndex = 1;

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                ProcessFile.ConvertStackup2ADDesignRule file = new ProcessFile.ConvertStackup2ADDesignRule(txtIcd.Text);
                string content = file.ConvertADDesignRule();
                using (TextWriter tw = new StreamWriter(saveFileDialog1.FileName, false, Encoding.GetEncoding(1252)))
                    tw.Write(content);
                MessageBox.Show("Done!");
            } 
        }

        
    }
}
